<?php


abstract class BaseCliente extends BaseObject  implements Persistent {


  const PEER = 'ClientePeer';

	
	protected static $peer;

	
	protected $id;

	
	protected $user_id;

	
	protected $nombre;

	
	protected $apellido_p;

	
	protected $apellido_m;

	
	protected $usuario;

	
	protected $password;

	
	protected $birthday;

	
	protected $telefono;

	
	protected $email;

	
	protected $tipo;

	
	protected $fecha;

	
	protected $activo;

	
	protected $asfGuardUser;

	
	protected $collRedsRelatedByClienteId;

	
	private $lastRedRelatedByClienteIdCriteria = null;

	
	protected $collRedsRelatedByAgregado;

	
	private $lastRedRelatedByAgregadoCriteria = null;

	
	protected $collVentas;

	
	private $lastVentaCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
		$this->tipo = 'B';
		$this->activo = true;
	}

	
	public function getId()
	{
		return $this->id;
	}

	
	public function getUserId()
	{
		return $this->user_id;
	}

	
	public function getNombre()
	{
		return $this->nombre;
	}

	
	public function getApellidoP()
	{
		return $this->apellido_p;
	}

	
	public function getApellidoM()
	{
		return $this->apellido_m;
	}

	
	public function getUsuario()
	{
		return $this->usuario;
	}

	
	public function getPassword()
	{
		return $this->password;
	}

	
	public function getBirthday($format = 'Y-m-d')
	{
		if ($this->birthday === null) {
			return null;
		}


		if ($this->birthday === '0000-00-00') {
									return null;
		} else {
			try {
				$dt = new DateTime($this->birthday);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->birthday, true), $x);
			}
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getTelefono()
	{
		return $this->telefono;
	}

	
	public function getEmail()
	{
		return $this->email;
	}

	
	public function getTipo()
	{
		return $this->tipo;
	}

	
	public function getFecha($format = 'Y-m-d')
	{
		if ($this->fecha === null) {
			return null;
		}


		if ($this->fecha === '0000-00-00') {
									return null;
		} else {
			try {
				$dt = new DateTime($this->fecha);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->fecha, true), $x);
			}
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getActivo()
	{
		return $this->activo;
	}

	
	public function setId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = ClientePeer::ID;
		}

		return $this;
	} 
	
	public function setUserId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = ClientePeer::USER_ID;
		}

		if ($this->asfGuardUser !== null && $this->asfGuardUser->getId() !== $v) {
			$this->asfGuardUser = null;
		}

		return $this;
	} 
	
	public function setNombre($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->nombre !== $v) {
			$this->nombre = $v;
			$this->modifiedColumns[] = ClientePeer::NOMBRE;
		}

		return $this;
	} 
	
	public function setApellidoP($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->apellido_p !== $v) {
			$this->apellido_p = $v;
			$this->modifiedColumns[] = ClientePeer::APELLIDO_P;
		}

		return $this;
	} 
	
	public function setApellidoM($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->apellido_m !== $v) {
			$this->apellido_m = $v;
			$this->modifiedColumns[] = ClientePeer::APELLIDO_M;
		}

		return $this;
	} 
	
	public function setUsuario($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->usuario !== $v) {
			$this->usuario = $v;
			$this->modifiedColumns[] = ClientePeer::USUARIO;
		}

		return $this;
	} 
	
	public function setPassword($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->password !== $v) {
			$this->password = $v;
			$this->modifiedColumns[] = ClientePeer::PASSWORD;
		}

		return $this;
	} 
	
	public function setBirthday($v)
	{
						if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->birthday !== null || $dt !== null ) {
			
			$currNorm = ($this->birthday !== null && $tmpDt = new DateTime($this->birthday)) ? $tmpDt->format('Y-m-d') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->birthday = ($dt ? $dt->format('Y-m-d') : null);
				$this->modifiedColumns[] = ClientePeer::BIRTHDAY;
			}
		} 
		return $this;
	} 
	
	public function setTelefono($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->telefono !== $v) {
			$this->telefono = $v;
			$this->modifiedColumns[] = ClientePeer::TELEFONO;
		}

		return $this;
	} 
	
	public function setEmail($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->email !== $v) {
			$this->email = $v;
			$this->modifiedColumns[] = ClientePeer::EMAIL;
		}

		return $this;
	} 
	
	public function setTipo($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->tipo !== $v || $v === 'B') {
			$this->tipo = $v;
			$this->modifiedColumns[] = ClientePeer::TIPO;
		}

		return $this;
	} 
	
	public function setFecha($v)
	{
						if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->fecha !== null || $dt !== null ) {
			
			$currNorm = ($this->fecha !== null && $tmpDt = new DateTime($this->fecha)) ? $tmpDt->format('Y-m-d') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->fecha = ($dt ? $dt->format('Y-m-d') : null);
				$this->modifiedColumns[] = ClientePeer::FECHA;
			}
		} 
		return $this;
	} 
	
	public function setActivo($v)
	{
		if ($v !== null) {
			$v = (boolean) $v;
		}

		if ($this->activo !== $v || $v === true) {
			$this->activo = $v;
			$this->modifiedColumns[] = ClientePeer::ACTIVO;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(ClientePeer::TIPO,ClientePeer::ACTIVO))) {
				return false;
			}

			if ($this->tipo !== 'B') {
				return false;
			}

			if ($this->activo !== true) {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->user_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
			$this->nombre = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
			$this->apellido_p = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->apellido_m = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->usuario = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->password = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
			$this->birthday = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
			$this->telefono = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
			$this->email = ($row[$startcol + 9] !== null) ? (string) $row[$startcol + 9] : null;
			$this->tipo = ($row[$startcol + 10] !== null) ? (string) $row[$startcol + 10] : null;
			$this->fecha = ($row[$startcol + 11] !== null) ? (string) $row[$startcol + 11] : null;
			$this->activo = ($row[$startcol + 12] !== null) ? (boolean) $row[$startcol + 12] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 13; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Cliente object", $e);
		}
	}

	
	public function ensureConsistency()
	{

		if ($this->asfGuardUser !== null && $this->user_id !== $this->asfGuardUser->getId()) {
			$this->asfGuardUser = null;
		}
	} 
	
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ClientePeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = ClientePeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); 
		if ($deep) {  
			$this->asfGuardUser = null;
			$this->collRedsRelatedByClienteId = null;
			$this->lastRedRelatedByClienteIdCriteria = null;

			$this->collRedsRelatedByAgregado = null;
			$this->lastRedRelatedByAgregadoCriteria = null;

			$this->collVentas = null;
			$this->lastVentaCriteria = null;

		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ClientePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			ClientePeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ClientePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			ClientePeer::addInstanceToPool($this);
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

												
			if ($this->asfGuardUser !== null) {
				if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) {
					$affectedRows += $this->asfGuardUser->save($con);
				}
				$this->setsfGuardUser($this->asfGuardUser);
			}

			if ($this->isNew() ) {
				$this->modifiedColumns[] = ClientePeer::ID;
			}

						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = ClientePeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += ClientePeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			if ($this->collRedsRelatedByClienteId !== null) {
				foreach ($this->collRedsRelatedByClienteId as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collRedsRelatedByAgregado !== null) {
				foreach ($this->collRedsRelatedByAgregado as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collVentas !== null) {
				foreach ($this->collVentas as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->asfGuardUser !== null) {
				if (!$this->asfGuardUser->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->asfGuardUser->getValidationFailures());
				}
			}


			if (($retval = ClientePeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collRedsRelatedByClienteId !== null) {
					foreach ($this->collRedsRelatedByClienteId as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collRedsRelatedByAgregado !== null) {
					foreach ($this->collRedsRelatedByAgregado as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collVentas !== null) {
					foreach ($this->collVentas as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ClientePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getUserId();
				break;
			case 2:
				return $this->getNombre();
				break;
			case 3:
				return $this->getApellidoP();
				break;
			case 4:
				return $this->getApellidoM();
				break;
			case 5:
				return $this->getUsuario();
				break;
			case 6:
				return $this->getPassword();
				break;
			case 7:
				return $this->getBirthday();
				break;
			case 8:
				return $this->getTelefono();
				break;
			case 9:
				return $this->getEmail();
				break;
			case 10:
				return $this->getTipo();
				break;
			case 11:
				return $this->getFecha();
				break;
			case 12:
				return $this->getActivo();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = ClientePeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getUserId(),
			$keys[2] => $this->getNombre(),
			$keys[3] => $this->getApellidoP(),
			$keys[4] => $this->getApellidoM(),
			$keys[5] => $this->getUsuario(),
			$keys[6] => $this->getPassword(),
			$keys[7] => $this->getBirthday(),
			$keys[8] => $this->getTelefono(),
			$keys[9] => $this->getEmail(),
			$keys[10] => $this->getTipo(),
			$keys[11] => $this->getFecha(),
			$keys[12] => $this->getActivo(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ClientePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setUserId($value);
				break;
			case 2:
				$this->setNombre($value);
				break;
			case 3:
				$this->setApellidoP($value);
				break;
			case 4:
				$this->setApellidoM($value);
				break;
			case 5:
				$this->setUsuario($value);
				break;
			case 6:
				$this->setPassword($value);
				break;
			case 7:
				$this->setBirthday($value);
				break;
			case 8:
				$this->setTelefono($value);
				break;
			case 9:
				$this->setEmail($value);
				break;
			case 10:
				$this->setTipo($value);
				break;
			case 11:
				$this->setFecha($value);
				break;
			case 12:
				$this->setActivo($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ClientePeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setUserId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setNombre($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setApellidoP($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setApellidoM($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setUsuario($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setPassword($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setBirthday($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setTelefono($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setEmail($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setTipo($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setFecha($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setActivo($arr[$keys[12]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(ClientePeer::DATABASE_NAME);

		if ($this->isColumnModified(ClientePeer::ID)) $criteria->add(ClientePeer::ID, $this->id);
		if ($this->isColumnModified(ClientePeer::USER_ID)) $criteria->add(ClientePeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(ClientePeer::NOMBRE)) $criteria->add(ClientePeer::NOMBRE, $this->nombre);
		if ($this->isColumnModified(ClientePeer::APELLIDO_P)) $criteria->add(ClientePeer::APELLIDO_P, $this->apellido_p);
		if ($this->isColumnModified(ClientePeer::APELLIDO_M)) $criteria->add(ClientePeer::APELLIDO_M, $this->apellido_m);
		if ($this->isColumnModified(ClientePeer::USUARIO)) $criteria->add(ClientePeer::USUARIO, $this->usuario);
		if ($this->isColumnModified(ClientePeer::PASSWORD)) $criteria->add(ClientePeer::PASSWORD, $this->password);
		if ($this->isColumnModified(ClientePeer::BIRTHDAY)) $criteria->add(ClientePeer::BIRTHDAY, $this->birthday);
		if ($this->isColumnModified(ClientePeer::TELEFONO)) $criteria->add(ClientePeer::TELEFONO, $this->telefono);
		if ($this->isColumnModified(ClientePeer::EMAIL)) $criteria->add(ClientePeer::EMAIL, $this->email);
		if ($this->isColumnModified(ClientePeer::TIPO)) $criteria->add(ClientePeer::TIPO, $this->tipo);
		if ($this->isColumnModified(ClientePeer::FECHA)) $criteria->add(ClientePeer::FECHA, $this->fecha);
		if ($this->isColumnModified(ClientePeer::ACTIVO)) $criteria->add(ClientePeer::ACTIVO, $this->activo);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(ClientePeer::DATABASE_NAME);

		$criteria->add(ClientePeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setUserId($this->user_id);

		$copyObj->setNombre($this->nombre);

		$copyObj->setApellidoP($this->apellido_p);

		$copyObj->setApellidoM($this->apellido_m);

		$copyObj->setUsuario($this->usuario);

		$copyObj->setPassword($this->password);

		$copyObj->setBirthday($this->birthday);

		$copyObj->setTelefono($this->telefono);

		$copyObj->setEmail($this->email);

		$copyObj->setTipo($this->tipo);

		$copyObj->setFecha($this->fecha);

		$copyObj->setActivo($this->activo);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach ($this->getRedsRelatedByClienteId() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addRedRelatedByClienteId($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getRedsRelatedByAgregado() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addRedRelatedByAgregado($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getVentas() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addVenta($relObj->copy($deepCopy));
				}
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new ClientePeer();
		}
		return self::$peer;
	}

	
	public function setsfGuardUser(sfGuardUser $v = null)
	{
		if ($v === null) {
			$this->setUserId(NULL);
		} else {
			$this->setUserId($v->getId());
		}

		$this->asfGuardUser = $v;

						if ($v !== null) {
			$v->addCliente($this);
		}

		return $this;
	}


	
	public function getsfGuardUser(PropelPDO $con = null)
	{
		if ($this->asfGuardUser === null && ($this->user_id !== null)) {
			$c = new Criteria(sfGuardUserPeer::DATABASE_NAME);
			$c->add(sfGuardUserPeer::ID, $this->user_id);
			$this->asfGuardUser = sfGuardUserPeer::doSelectOne($c, $con);
			
		}
		return $this->asfGuardUser;
	}

	
	public function clearRedsRelatedByClienteId()
	{
		$this->collRedsRelatedByClienteId = null; 	}

	
	public function initRedsRelatedByClienteId()
	{
		$this->collRedsRelatedByClienteId = array();
	}

	
	public function getRedsRelatedByClienteId($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ClientePeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collRedsRelatedByClienteId === null) {
			if ($this->isNew()) {
			   $this->collRedsRelatedByClienteId = array();
			} else {

				$criteria->add(RedPeer::CLIENTE_ID, $this->id);

				RedPeer::addSelectColumns($criteria);
				$this->collRedsRelatedByClienteId = RedPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(RedPeer::CLIENTE_ID, $this->id);

				RedPeer::addSelectColumns($criteria);
				if (!isset($this->lastRedRelatedByClienteIdCriteria) || !$this->lastRedRelatedByClienteIdCriteria->equals($criteria)) {
					$this->collRedsRelatedByClienteId = RedPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastRedRelatedByClienteIdCriteria = $criteria;
		return $this->collRedsRelatedByClienteId;
	}

	
	public function countRedsRelatedByClienteId(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ClientePeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collRedsRelatedByClienteId === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(RedPeer::CLIENTE_ID, $this->id);

				$count = RedPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(RedPeer::CLIENTE_ID, $this->id);

				if (!isset($this->lastRedRelatedByClienteIdCriteria) || !$this->lastRedRelatedByClienteIdCriteria->equals($criteria)) {
					$count = RedPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collRedsRelatedByClienteId);
				}
			} else {
				$count = count($this->collRedsRelatedByClienteId);
			}
		}
		$this->lastRedRelatedByClienteIdCriteria = $criteria;
		return $count;
	}

	
	public function addRedRelatedByClienteId(Red $l)
	{
		if ($this->collRedsRelatedByClienteId === null) {
			$this->initRedsRelatedByClienteId();
		}
		if (!in_array($l, $this->collRedsRelatedByClienteId, true)) { 			array_push($this->collRedsRelatedByClienteId, $l);
			$l->setClienteRelatedByClienteId($this);
		}
	}

	
	public function clearRedsRelatedByAgregado()
	{
		$this->collRedsRelatedByAgregado = null; 	}

	
	public function initRedsRelatedByAgregado()
	{
		$this->collRedsRelatedByAgregado = array();
	}

	
	public function getRedsRelatedByAgregado($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ClientePeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collRedsRelatedByAgregado === null) {
			if ($this->isNew()) {
			   $this->collRedsRelatedByAgregado = array();
			} else {

				$criteria->add(RedPeer::AGREGADO, $this->id);

				RedPeer::addSelectColumns($criteria);
				$this->collRedsRelatedByAgregado = RedPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(RedPeer::AGREGADO, $this->id);

				RedPeer::addSelectColumns($criteria);
				if (!isset($this->lastRedRelatedByAgregadoCriteria) || !$this->lastRedRelatedByAgregadoCriteria->equals($criteria)) {
					$this->collRedsRelatedByAgregado = RedPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastRedRelatedByAgregadoCriteria = $criteria;
		return $this->collRedsRelatedByAgregado;
	}

	
	public function countRedsRelatedByAgregado(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ClientePeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collRedsRelatedByAgregado === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(RedPeer::AGREGADO, $this->id);

				$count = RedPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(RedPeer::AGREGADO, $this->id);

				if (!isset($this->lastRedRelatedByAgregadoCriteria) || !$this->lastRedRelatedByAgregadoCriteria->equals($criteria)) {
					$count = RedPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collRedsRelatedByAgregado);
				}
			} else {
				$count = count($this->collRedsRelatedByAgregado);
			}
		}
		$this->lastRedRelatedByAgregadoCriteria = $criteria;
		return $count;
	}

	
	public function addRedRelatedByAgregado(Red $l)
	{
		if ($this->collRedsRelatedByAgregado === null) {
			$this->initRedsRelatedByAgregado();
		}
		if (!in_array($l, $this->collRedsRelatedByAgregado, true)) { 			array_push($this->collRedsRelatedByAgregado, $l);
			$l->setClienteRelatedByAgregado($this);
		}
	}

	
	public function clearVentas()
	{
		$this->collVentas = null; 	}

	
	public function initVentas()
	{
		$this->collVentas = array();
	}

	
	public function getVentas($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ClientePeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collVentas === null) {
			if ($this->isNew()) {
			   $this->collVentas = array();
			} else {

				$criteria->add(VentaPeer::CLIENTE_ID, $this->id);

				VentaPeer::addSelectColumns($criteria);
				$this->collVentas = VentaPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(VentaPeer::CLIENTE_ID, $this->id);

				VentaPeer::addSelectColumns($criteria);
				if (!isset($this->lastVentaCriteria) || !$this->lastVentaCriteria->equals($criteria)) {
					$this->collVentas = VentaPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastVentaCriteria = $criteria;
		return $this->collVentas;
	}

	
	public function countVentas(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ClientePeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collVentas === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(VentaPeer::CLIENTE_ID, $this->id);

				$count = VentaPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(VentaPeer::CLIENTE_ID, $this->id);

				if (!isset($this->lastVentaCriteria) || !$this->lastVentaCriteria->equals($criteria)) {
					$count = VentaPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collVentas);
				}
			} else {
				$count = count($this->collVentas);
			}
		}
		$this->lastVentaCriteria = $criteria;
		return $count;
	}

	
	public function addVenta(Venta $l)
	{
		if ($this->collVentas === null) {
			$this->initVentas();
		}
		if (!in_array($l, $this->collVentas, true)) { 			array_push($this->collVentas, $l);
			$l->setCliente($this);
		}
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			if ($this->collRedsRelatedByClienteId) {
				foreach ((array) $this->collRedsRelatedByClienteId as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collRedsRelatedByAgregado) {
				foreach ((array) $this->collRedsRelatedByAgregado as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collVentas) {
				foreach ((array) $this->collVentas as $o) {
					$o->clearAllReferences($deep);
				}
			}
		} 
		$this->collRedsRelatedByClienteId = null;
		$this->collRedsRelatedByAgregado = null;
		$this->collVentas = null;
			$this->asfGuardUser = null;
	}

} 